#!/usr/bin/python3
from math import floor


def get_index(n):
    if n < 2 :
        return n
    else:
        m = get_index(floor(n/2))
        return 2 * m + (n % 2 + m % 2) % 2


try:
    n = int(input())
    print(get_index(n) + 1)
except ValueError:
    pass
except EOFError:
    pass
except MemoryError:
    pass
